<template>
<div>
	<x-dialog v-model="show" style="width:100%">
		<div class="weui-dialog__hd showContent">
			<strong class="weui-dialog__title">{{name}}</strong>
		</div>
		<div class="weui-dialog__bd">
			<divider>加签人</divider>
			<flexbox :gutter="0" wrap="wrap">
				<flexbox-item :span="1/3"  v-for="(item,index) in users" :key="index">
					<x-button type="warn" class="fa fa-close " style="margin-top:5px;" :mini="true" @click.native="removeUser(index)">{{item.name}}</x-button>
				</flexbox-item>
				<flexbox-item :span="1/2">
					<ab-cust-dialog style="margin-top:5px;" :dialogSetting="{displayFields:[{showName:'姓名',columnName:'fullname'}],multiple:true}" dialogKey="userSelector" :model="newUsers">自由选择</ab-cust-dialog>
				</flexbox-item>
			</flexbox>
		</div>
		<div class="weui-dialog__ft">
			<a class="weui-dialog__btn weui-dialog__btn_default" v-on:click="ok()">确定</a>
			<a class="weui-dialog__btn weui-dialog__btn_default" v-on:click="cancel()">取消</a>
		</div>
	</x-dialog>
</div>
</template>

<script>
import Vue from 'vue'
export default {
	props:['passConf','showDialog','name'],
  	data :function () {
    	return {
	    	flowParam:this.passConf,
	   		show : false,
	   		users : [],
	   		msgList : [],
	   		newUsers : [],
	   		msgType : "",
	    }
   	},
   	methods: {
    	ok:function(){
    		if(this.users.length==0){
	    		Vue.tools.toast("请选择加签人员！","warn");
	    		return ;
	    	}
	    	this.flowParam.extendConf = {
	    		users : this.users,
	    	};
	    	this.show = false;
	    	this.$emit('callback',this.flowParam);
	    },
		cancel:function(){
			this.show = false;
			this.$emit('cancel',this.flowParam);
		},
		addUser : function(user){
	    	var exist = false;
	    	this.users.forEach(function(item){
	    		if(item.id==user.id){
	    			exist = true;
	    		}
	    	});
	    	if(!exist){
	    		this.users.push(user);
	    	}
	    },
	    removeUser : function(index){
	    	this.users.splice(index,1);
	    },
   },
   watch:{
	   	showDialog:function(value,oldValue){
		   	this.show = value;
	   	},
		newUsers : function(newVal,oldVal){
		   	if(newVal.length==0){
			   	return;
		   	}
		   	var that = this;
		   	this.newUsers.forEach(function(item){
			   	that.addUser({
				   	id : item.id,
					name : item.name,
					type : "user"//用户
			   	});
		   	});
		   	this.newUsers = [];
		}
 	},
   	created :function(){
   		var that = this;
   		this.show = this.showDialog;
   	}
}
</script>
